package com.kexuexiong.demo.bear.common.config.shiro.realm;

import org.apache.shiro.authc.*;
import org.apache.shiro.realm.Realm;

import java.util.Objects;

public class MyRealm3 implements Realm {
    @Override
    public String getName() {
        return "myRealm1";
    }

    @Override
    public boolean supports(AuthenticationToken token) {
        return token instanceof UsernamePasswordToken;
    }

    @Override
    public AuthenticationInfo getAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        String password = new String((char[]) token.getCredentials());
        String userName = (String) token.getPrincipal();

        if (!Objects.equals(userName, "zhang")) {
            throw new UnknownAccountException();
        }

        if (!Objects.equals(password, "123")) {
            throw new IncorrectCredentialsException();
        }

        return new SimpleAuthenticationInfo(userName, "zhang@1170313408@qq.com", getName());
    }
}
